/**
 * Project Name:kany-project-spring-boot
 * File Name:JavaMelodyConfig.java
 * Package Name:me.kany.project.spring.boot.javamelody
 * Date:2016年5月11日下午1:58:50
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 *
*/

package me.kany.project.spring.boot.config.javamelody;

import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import me.kany.project.spring.boot.config.mybatis.MyBatisConfig;
import net.bull.javamelody.MonitoringSpringAdvisor;
import net.bull.javamelody.SpringDataSourceBeanPostProcessor;
import net.bull.javamelody.SpringDataSourceFactoryBean;

/**
 * ClassName:JavaMelodyConfig <br/>
 * Function: JavaMelody的配置文件. <br/>
 * Date:     2016年5月11日 下午1:58:50 <br/>
 * @author   Jason.Wang
 * @version  
 * @since    JDK 1.7
 * @see 	 
 */
@Configuration
@AutoConfigureAfter(MyBatisConfig.class)
@ImportResource("classpath:net/bull/javamelody/monitoring-spring.xml")
public class JavaMelodyConfig {
	
    /**
     * 设置默认的spring方法的代理
     * @return
     */
    @Bean(name="facadeMonitoringAdvisor")
    public MonitoringSpringAdvisor monitoringSpringAdvisor(){
        MonitoringSpringAdvisor monitoringSpringAdvisor = new MonitoringSpringAdvisor();
        JdkRegexpMethodPointcut jdkRegexpMethodPointcut = new JdkRegexpMethodPointcut();
        jdkRegexpMethodPointcut.setPatterns("me.kany.project.*.*.service.*.*","me.kany.project.*.*.mapper.*.*");
        monitoringSpringAdvisor.setPointcut(jdkRegexpMethodPointcut);
        return monitoringSpringAdvisor;
    }

    /**
     * 获取JavaMelody的Spring的DataBase的对象
     * @return
     */
    @Bean(name = "springDataSourceBeanPostProcessor")
    public SpringDataSourceBeanPostProcessor springDataSourceBeanPostProcessor(){
        SpringDataSourceBeanPostProcessor springDataSourceBeanPostProcessor = new SpringDataSourceBeanPostProcessor();
        return springDataSourceBeanPostProcessor;
    }

    /**
     * 开启监听
     * @return
     */
    @Bean(name = "wrappedDataSource")
    public SpringDataSourceFactoryBean springDataSourceFactoryBean(){
        SpringDataSourceFactoryBean springDataSourceFactoryBean = new SpringDataSourceFactoryBean();
        springDataSourceFactoryBean.setTargetName("dataSource");
        return springDataSourceFactoryBean;
    }
}
